﻿using BunnyEater.Common.Const;
using Microsoft.Extensions.DependencyInjection;

namespace BunnyEater.WebAPI.Extensions
{
    public static class CorsServiceRegister
    {
        /// <summary>
        /// 注册跨域
        /// </summary>
        /// <param name="serviceCollection"></param>
        /// <returns></returns>
        public static IServiceCollection CorsRegister(this IServiceCollection serviceCollection)
        {
            serviceCollection.AddCors(op =>
            {
                op.AddPolicy(AssemblyConst.PROGRAM_CORS_POLICY, policy =>
                {
                    policy.AllowAnyHeader()
                    .AllowAnyOrigin()
                    .AllowAnyMethod();
                });
            });

            return serviceCollection;
        }
    }
}
